<template>
  <form>
    <v-text-field v-model="data.user.nickname" label="公司名称"></v-text-field>
    <v-text-field v-model="data.user.address" label="地址"></v-text-field>
    <v-select
      v-model="data.user.sex"
      :items="items"
      label="性别"
      @change="$v.select.$touch()"
      @blur="$v.select.$touch()"
    ></v-select>
    <!-- <v-checkbox
      v-model="checkbox"
      :error-messages="checkboxErrors"
      label="Do you agree?"
      required
      @change="$v.checkbox.$touch()"
      @blur="$v.checkbox.$touch()"
    ></v-checkbox> -->
    <div v-for="(item, index) in data.hospital" :key="index">
      <p class="text-h6 mt-6">{{item.name}}</p>
      <v-simple-table>
        <template v-slot:default>
          <thead>
            <tr>
              <th class="text-left">医生姓名</th>
              <th class="text-left">手机号</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(doctor, doctorIndex) in item.doctor" :key="doctorIndex">
              <td>{{ doctor.name }}</td>
              <td>{{ doctor.mobile }}</td>
            </tr>
          </tbody>
        </template>
      </v-simple-table>
    </div>

    <v-btn color="primary" class="mr-4 mt-10" @click="submit">提交</v-btn>
    <v-btn class="mt-10" @click="goback">返回</v-btn>
  </form>
</template>

<script>
import { validationMixin } from "vuelidate";
import { required, maxLength, email } from "vuelidate/lib/validators";

export default {
  mixins: [validationMixin],

  validations: {
    name: { required, maxLength: maxLength(10) },
  },

  data: () => ({
    id: null,
    items: [
      { text: "男", value: 1 },
      { text: "女", value: 2 },
    ],
    data: {
      saleName: "",
      hospital: "",
      name: "",
      mobile: "",
      HospitalID: "",
      id: "",
      sellerid: "",
      ROW_NUMBER: "",
      user: {
        deleteAt: null,
        name: null,
        openId: null,
        image: null,
        mobile: "",
        nickname: "",
        account: "0.00",
        accessToken: null,
        refreshToken: null,
        address: null,
      },
    },
  }),

  created() {
    this.id = this.$route.query.id;
    this.getData();
  },

  computed: {},

  methods: {
    getData() {
      this.Http.get("/admin/user/detail", {
        id: this.id,
      }).then((res) => {
        if (res.code == 1) {
          this.data = res.data;
        } else {
          this.$Message.error(res.msg);
        }
      });
    },
    submit() {
      const _this = this;
      this.Http.post("/admin/user/update", {
        id: this.id,
        nickname: this.data.user.nickname,
        address: this.data.user.address,
        sex: this.data.user.sex,
      }).then((res) => {
        if (res.code == 1) {
          this.$Message.success(res.msg);
          setTimeout(() => {
            _this.$router.go(-1);
          }, 1500);
        } else {
          this.$Message.error(res.msg);
        }
      });
    },
    goback() {
      this.$router.go(-1);
    },
  },
};
</script>